package net.lovesrc.allin.controller;

import net.lovesrc.allin.Message;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/config")
public class ConfigController extends BaseController {

    @PostMapping("/save-cmp-size")
    public Object saveCmpSize(String cmpId, Integer width) {

        String userId = getCurrentUserId();
        Integer qty = jdbcTemplate.queryForObject("select count(1) from t_cmp_size where cmpId = ? and userId = ?", Integer.class, cmpId, userId);
        if (qty == 0) {
            jdbcTemplate.update("insert into t_cmp_size(userId, cmpId, width) values(?, ?, ?)", userId, cmpId, width);
        } else {
            jdbcTemplate.update("update t_cmp_size set width = ? where userId = ? and cmpId = ?", width, userId, cmpId);
        }
        return Message.success();
    }

}